//

#import "MB_SearchHeaderView.h"

@implementation MB_SearchHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    if ([super initWithFrame:frame]) {
        self.backgroundColor = RGB(232, 232, 232);
        [self textFieldView];
    }
    return self;
}

//
- (void)textFieldView {
  
    self.searchBar = [[UITextField alloc]initWithFrame:CGRectMake(kRWidth(5), kRHeight(5), self.frame.size.width - kRWidth(10), self.frame.size.height - kRHeight(10))];
    self.searchBar.textColor = [UIColor blackColor];
    self.searchBar.backgroundColor = RGB(255, 255, 255);
    self.searchBar.font = FontPFRegular(kRWidth(16));
    self.searchBar.placeholder = @"Search";
    self.searchBar.delegate = self;
    self.searchBar.layer.cornerRadius = 6;
    [self.searchBar setValue:rgba(155, 155, 155, 1) forKeyPath:@"_placeholderLabel.textColor"];
    [self.searchBar addTarget:self action:@selector(textchange:) forControlEvents:UIControlEventEditingChanged];
    //设置
    UIView *leftView = [[UIView alloc ] initWithFrame:CGRectMake(0, kRHeight(1), kRWidth(28), kRHeight(28))];
    UIImageView * leftImage = [[UIImageView alloc] initWithFrame:CGRectMake(8, kRHeight(5), kRHeight(18), kRHeight(18))];
    leftImage.image = [UIImage imageNamed:@"post_course_search"];
    [leftView addSubview:leftImage];
    
    self.searchBar.leftView = leftView;
    self.searchBar.leftViewMode = UITextFieldViewModeAlways;
    [self addSubview:self.searchBar];
}

- (void)textchange:(UITextField*)obj {
    if ([self.delegate respondsToSelector:@selector(textFieldChange:)]) {
        [self.delegate textFieldChange:obj.text];
    }
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
